package com.easemob.analytics;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatConfig;
import com.easemob.chat.core.k;
import com.easemob.cloud.HttpClientManager;
import com.easemob.util.DeviceUuidFactory;
import com.easemob.util.EMLog;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.json.JSONObject;

public class ActiveCollector
{
  private static final String perf_actived = "actived";

  public static String collectActiveInfo(Context paramContext)
  {
    JSONObject localJSONObject = new JSONObject();
    try
    {
      localJSONObject.put("version", Build.VERSION.RELEASE);
      localJSONObject.put("manufacturer", Build.MANUFACTURER);
      localJSONObject.put("model", Build.MODEL);
      try
      {
        TelephonyManager localTelephonyManager = (TelephonyManager)paramContext.getSystemService("phone");
        localJSONObject.put("imei", localTelephonyManager.getDeviceId());
        localJSONObject.put("operator", localTelephonyManager.getNetworkOperatorName());
      }
      catch (Exception localException1)
      {
        if (localException1 != null)
          EMLog.d("actived", localException1.getMessage());
      }
      localJSONObject.put("easemob.version", EMChat.getInstance().getVersion());
      try
      {
        LocationManager localLocationManager = (LocationManager)paramContext.getSystemService("location");
        localObject = localLocationManager.getLastKnownLocation("gps");
        if (localObject == null)
          localObject = localLocationManager.getLastKnownLocation("network");
        if (localObject != null)
        {
          localJSONObject.put("loc.lat", ((Location)localObject).getLatitude());
          localJSONObject.put("loc.lng", ((Location)localObject).getLongitude());
        }
        else
        {
          EMLog.d("ana", "no last location info to use");
        }
      }
      catch (Exception localException2)
      {
        if (localException2 != null)
          EMLog.d("actived", localException2.getMessage());
      }
      DeviceUuidFactory localDeviceUuidFactory = new DeviceUuidFactory(paramContext);
      Object localObject = localDeviceUuidFactory.getDeviceUuid().toString();
      localJSONObject.put("token", localObject);
    }
    catch (Exception localException3)
    {
      if (localException3 != null)
        EMLog.d("actived", localException3.getMessage());
    }
    return localJSONObject.toString();
  }

  public static void sendActivePacket(Context paramContext)
  {
    boolean bool = PreferenceManager.getDefaultSharedPreferences(paramContext).getBoolean("actived", false);
    if (bool)
    {
      EMLog.d("init", "s");
      return;
    }
    try
    {
      EMLog.d("init", "d");
      new Thread(new Runnable()
      {
        public void run()
        {
          StringBuilder localStringBuilder = new StringBuilder();
          if (EMChatConfig.getInstance().getIsHttps())
            localStringBuilder.append("https://");
          else
            localStringBuilder.append("http://");
          String str1 = k.a().h();
          if (str1.startsWith("http"))
            localStringBuilder = new StringBuilder(str1);
          else
            localStringBuilder.append(str1);
          localStringBuilder.append("/");
          localStringBuilder.append(EMChatConfig.getInstance().APPKEY.replaceFirst("#", "/"));
          localStringBuilder.append("/devices");
          String str2 = null;
          try
          {
            String str3 = ActiveCollector.collectActiveInfo(ActiveCollector.this);
            localObject = new HashMap();
            str2 = HttpClientManager.sendHttpRequest(localStringBuilder.toString(), (Map)localObject, str3, HttpClientManager.Method_POST);
            if ((str2.contains("uuid")) || (str2.contains("duplicate_unique_property_exists")))
            {
              SharedPreferences.Editor localEditor = PreferenceManager.getDefaultSharedPreferences(ActiveCollector.this).edit();
              localEditor.putBoolean("actived", true);
              localEditor.commit();
            }
          }
          catch (Exception localException)
          {
            Object localObject;
            if (localException.toString().contains("duplicate_unique"))
            {
              localObject = PreferenceManager.getDefaultSharedPreferences(ActiveCollector.this).edit();
              ((SharedPreferences.Editor)localObject).putBoolean("actived", true);
              ((SharedPreferences.Editor)localObject).commit();
            }
          }
        }
      }).start();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void sendUninstallPacket()
  {
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.analytics.ActiveCollector
 * JD-Core Version:    0.6.1
 */